package com.tour.modules.web.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tour.common.utils.PageUtils;
import com.tour.common.utils.Query;
import com.tour.common.utils.R;
import com.tour.modules.web.entity.TNewsEntity;
import com.tour.modules.web.service.TNewsService;

/**
 * 新闻表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-01-06 22:44:15
 */
@RestController
@RequestMapping("tnews")
public class TNewsController {
	@Autowired
	private TNewsService tNewsService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);

		List<TNewsEntity> tNewsList = tNewsService.queryList(query);
		int total = tNewsService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(tNewsList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id) {
		TNewsEntity tNews = tNewsService.queryObject(id);

		return R.ok().put("tNews", tNews);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody TNewsEntity tNews) {
		tNewsService.save(tNews);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody TNewsEntity tNews) {
		tNewsService.update(tNews);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids) {
		tNewsService.deleteBatch(ids);

		return R.ok();
	}

}
